package com.hyts.schedule.executor.Job;

import com.hyts.aop.annotation.After;
import com.hyts.aop.annotation.Before;
import com.hyts.aop.annotation.Weave;
import com.hyts.jlogger.manager.LoggerManager;

import java.util.Arrays;
import java.util.logging.Logger;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.guava.monitor
 * author:Libo/Alex
 * create-date:2019-05-08 22:43
 * copyright:libo-hyts-github
 * email:libo2dev@aliyun.com
 * description:此类主要用于: 执行操作服务监控
 */
@Weave
public class CallMonitor {

    Logger logger = LoggerManager.getLogger(CallMonitor.class);

    ThreadLocal<Long> callSpendTime = new ThreadLocal<>();

    @Before
    public void before(){
        callSpendTime.set(System.currentTimeMillis());
    }

    @After
    public void after(){
       Long executeTime = System.currentTimeMillis() - callSpendTime.get();
       StackTraceElement[] stackTraceElements =  Thread.currentThread().getStackTrace();
       int lw = stackTraceElements.length;
       System.out.println(Arrays.toString(stackTraceElements));
       logger.info("来自"+stackTraceElements[0]+"的调用");
       logger.info("执行时间："+executeTime+"ms");
    }

}
